import Vue from 'vue'
import App from './App.vue'
import store from './store'
import router from './router/index.js'
import public_c from './public_c.js'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/base.css'
import './assets/css/iconfont.css'
import './assets/css/style.css'
import './assets/css/jianrong.css'
import api from './api/install'
import '@/util'
Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(public_c);
Vue.use(api);
router.beforeEach((to, from, next) => {
    store.state.hx = to.meta.index
    // 获取屏幕的高度
    store.state.clientHeight = document.body.clientHeight
    store.state.routeNmae = to.meta.title
    store.state.keepAlive = to.meta.keepAlive
    store.state.routetname =  to.name
    if (store.state.jilulist.length <= 0) {
        try{
           store.state.jilulist = JSON.parse(localStorage.jilulist) 
        }catch(e){
            store.state.jilulist =[]
        }
        
    }
    if (to.name == 'Login') {
        store.state.isLogin = true
        next()
        return
    }
    store.state.isLogin = false
    if (to.name) {
        store.state.jilulist.push(to)
        store.state.jilulist = unique(store.state.jilulist, 'name')
        store.state.jilulist.map(a => {
            a.meta.act = ''
            if (a.name == to.name) {
                a.meta.act = 'act'
            }
        })
        try {
            localStorage.jilulist = JSON.stringify(store.state.jilulist)
        } catch (e) {

        }
    }
    next()
})
// 数组对象去重
function unique(arr, name) {
    const res = new Map();
    return arr.filter(
        (a) => !res.has(a[name]) && res.set(a[name], 1)
    )
}
new Vue({
    store,
    router,
    render: h => h(App)
}).$mount('#app')
